home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 October: Technology Seed / ADC Seed CD - October 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / CDEFTesterUtils.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  52.2 KB  |  1,859 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CDEFTesterUtils.cp
  3.  
  4.     Contains:    Code to demonstrate creating and using all types of controls.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (jss)    Jeff Shulman
  21.         (MAA)    Matt Ackeret
  22.         (edv)    Ed Voas
  23.  
  24.     Change History (most recent first):
  25.  
  26.        <1.9>      4/7/99    jss        Fix CarbonLib compilation problems
  27.         <14>      6/8/98    MAA        Added title for triangle (not drawn in Allegro)
  28.         <13>     2/18/98    MAA        Add list control
  29.         <12>     1/22/98    MAA        Add support for auto-toggle variants for checkbox/radio button
  30.         <11>    12/18/97    edv        Fix compiler warnings.
  31.         <10>    11/21/97    MAA        Add UserPane
  32.          <9>     11/7/97    MAA        Remove tab count limitation
  33.          <8>     11/6/97    MAA        Make tab names variable length.
  34.          <7>     11/5/97    MAA        add Tabs
  35.          <6>    10/31/97    MAA        fix window title in CreateCheckBoxOrRadioButton
  36.          <5>    10/31/97    MAA        fix clock size in CreateClock
  37.          <4>    10/28/97    MAA        Remove temporary editText control bug checking code
  38.          <3>    10/28/97    MAA        Create many dialogs invisible then show after changes made
  39.          <2>    10/28/97    edv        Use RadioGroup control!
  40.          <1>     9/11/97    edv        First checked in.
  41. */
  42.  
  43. #include "AppearanceSamplePrefix.h"
  44.  
  45. #include <TextUtils.h>
  46. #include <Appearance.h>
  47. #include <Resources.h>
  48. #include <Controls.h>
  49. #include <ControlDefinitions.h>
  50. #include <Lists.h>
  51. #include <NumberFormatting.h>
  52. #include "CDEFTesterUtils.h"
  53. #include "BevelButtonItems.h"
  54. #include "RadioGroup.h"
  55. #include "AppearanceHelpers.h"
  56.  
  57. enum
  58. {
  59.     kLeftArrow        = 0x1C,
  60.     kRightArrow        = 0x1D,
  61.     kUpArrow        = 0x1E,
  62.     kDownArrow        = 0x1F,
  63.     kBackspace        = 0x08
  64. };
  65.  
  66. enum { kSmall = 1, kNormal, kLarge };
  67. enum { kMomentary = 1, kToggles, kSticky };
  68. enum { kTextOnly = 1, kIconSuite, kColorIcon, kPicture };
  69. enum { kPlaceNormal = 1, kPlaceLeft, kPlaceRight, kPlaceAbove, kPlaceBelow, kPlaceSys };
  70. enum { kTextSysDir = 1, kTextLeft, kTextRight, kTextCenter };
  71. enum { kGraphicSysDir = 1, kGraphicCenter, kGraphicLeft, kGraphicRight,
  72.         kGraphicTop, kGraphicBottom, kGraphicTopLeft, kGraphicBotLeft,
  73.         kGraphicTopRight, kGraphicBotRight };
  74.  
  75. static void                GetPictureSize( SInt16 resID, SInt32* height, SInt32* width );
  76. static void                GetIconSize( SInt16 resID, SInt32* height, SInt32* width );
  77. static ControlHandle    CreatePictureOrIconCDEF( WindowPtr window, Boolean isPicture );
  78. static ControlHandle    CreateCheckBoxOrRadioButton( WindowPtr window, Boolean isCheckBox );
  79. static pascal void        UserPaneDrawProc(ControlHandle theControl, SInt16 thePart);
  80.  
  81. ControlHandle
  82. CreateBevelButton( WindowPtr window )
  83. {
  84.     DialogPtr                        dialog;
  85.     SInt16                            itemHit = 0;
  86.     ControlRef                        control = nil;
  87.     SInt16                            type;
  88.     Handle                            handle;
  89.     Rect                            rect;
  90.     SInt32                            stringNumber;
  91.     ControlButtonContentInfo            content;
  92.     SInt16                            menuID;
  93.     ControlBevelThickness            thickness;
  94.     ControlBevelButtonBehavior        behavior;
  95.     ControlBevelButtonMenuBehavior    menuBehavior;
  96.     ControlBevelButtonMenuPlacement    menuPlacement;
  97.     Str255                            text, title;
  98.     Rect                            bounds = { 0, 0, 48, 48 };
  99.     
  100.     ControlButtonGraphicAlignment    graphicAlign;
  101.     ControlButtonTextPlacement        placement;
  102.     ControlButtonTextAlignment        alignment;
  103.     SInt32                            longOffset;
  104.     SInt16                            offset;
  105.     SInt32                            temp;
  106.     Point                            graphicOffset;
  107.     ControlHandle                    tempControl;
  108.     
  109.     dialog = GetNewDialog( 2000, nil, (WindowPtr)-1L );
  110.     if ( dialog == nil ) return nil;
  111.  
  112.     GetDialogItemAsControl( dialog, kBevelSizePopup, &tempControl );
  113.     SetControlValue( tempControl, kSmall );
  114.     
  115.     GetDialogItemAsControl( dialog, kBevelBehaviorPopup, &tempControl );
  116.     SetControlValue( tempControl, kMomentary );
  117.     
  118.     GetDialogItemAsControl( dialog, kBevelContentPopup, &tempControl );
  119.     SetControlValue( tempControl, kTextOnly );
  120.  
  121.     GetDialogItemAsControl( dialog, kBevelTextPlacePopup, &tempControl );
  122.     SetControlValue( tempControl, kPlaceNormal );
  123.  
  124.     GetDialogItemAsControl( dialog, kBevelTextAlignPopup, &tempControl );
  125.     SetControlValue( tempControl, kTextCenter );
  126.  
  127.     GetDialogItemAsControl( dialog, kBevelGraphicAlignPopup, &tempControl );
  128.     SetControlValue( tempControl, kGraphicCenter );
  129.  
  130.     SetDialogDefaultItem( dialog, kBevelOKButton );
  131.     SetDialogCancelItem( dialog, kBevelCancelButton );
  132.         
  133.     ShowWindow( GetDialogWindow( dialog ) );
  134.     
  135.     while ( itemHit != kBevelCancelButton && itemHit != kBevelOKButton )
  136.     {
  137.         ModalDialog( nil, &itemHit );
  138.         
  139.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  140.         switch ( itemHit )
  141.         {
  142.             case kBevelOffsetCheck:
  143.             case kBevelMultiMenuCheck:
  144.             case kBevelMenuOnRightCheck:
  145.                 {
  146.                     SInt16    value = GetControlValue( tempControl );
  147.                     SetControlValue( tempControl, !value );
  148.                 }
  149.                 break;
  150.  
  151.         }
  152.     }
  153.     
  154.     if ( itemHit == kBevelCancelButton )
  155.     {
  156.         DisposeDialog( dialog );
  157.         return nil;
  158.     }
  159.     
  160.         // Get the content type
  161.         
  162.     GetDialogItemAsControl( dialog, kBevelContentPopup, &tempControl );
  163.     switch ( GetControlValue( tempControl ) )
  164.     {
  165.         case kTextOnly:        content.contentType = kControlContentTextOnly;        break;
  166.         case kIconSuite:        content.contentType = kControlContentIconSuiteRes;    break;
  167.         case kColorIcon:        content.contentType = kControlContentCIconRes;        break;
  168.         case kPicture:        content.contentType = kControlContentPictRes;        break;
  169.     }
  170.     
  171.         // Now get the resource ID for the content, if we
  172.         // have chosen something other than text only.
  173.         
  174.     if ( content.contentType != kControlContentTextOnly )
  175.     {
  176.         GetDialogItem( dialog, kBevelContentIDText, &type, &handle, &rect );
  177.         GetDialogItemText( handle, text );
  178.         StringToNum( text, &stringNumber );
  179.         content.u.resID = stringNumber;
  180.     }
  181.     
  182.         // Get the menu
  183.         
  184.     GetDialogItem( dialog, kBevelMenuIDText, &type, &handle, &rect );
  185.     GetDialogItemText( handle, text );
  186.     StringToNum( text, &stringNumber );
  187.     menuID = stringNumber;
  188.  
  189.         // determine our bevel size
  190.     
  191.     GetDialogItemAsControl( dialog, kBevelSizePopup, &tempControl );
  192.     switch( GetControlValue( tempControl ) )
  193.     {
  194.         case kSmall:        thickness = kControlBevelButtonSmallBevel;        break;
  195.         default:
  196.         case kNormal:     thickness = kControlBevelButtonNormalBevel;     break;
  197.         case kLarge:     thickness = kControlBevelButtonLargeBevel;        break;
  198.     }
  199.  
  200.         // determine our behavior
  201.  
  202.     GetDialogItemAsControl( dialog, kBevelBehaviorPopup, &tempControl );
  203.     switch( GetControlValue( (ControlHandle)handle ) )
  204.     {
  205.         default:
  206.         case kMomentary:        behavior = kControlBehaviorPushbutton;    break;
  207.         case kToggles:        behavior = kControlBehaviorToggles;     break;
  208.         case kSticky:        behavior = kControlBehaviorSticky;        break;
  209.     }
  210.  
  211.         // See if we should offset the contents and or this into our behavior.
  212.         
  213.     GetDialogItemAsControl( dialog, kBevelOffsetCheck, &tempControl );
  214.     if ( GetControlValue( tempControl ) == 1 )
  215.         behavior |= kControlBehaviorOffsetContents;
  216.     
  217.         // See what our menu's behavior is.
  218.         
  219.     menuBehavior = kControlBehaviorSingleValueMenu;
  220.     GetDialogItemAsControl( dialog, kBevelMultiMenuCheck, &tempControl );
  221.     if ( GetControlValue( tempControl ) == 1 )
  222.         menuBehavior |= kControlBehaviorMultiValueMenu;
  223.     
  224.         // See if the menu shoule be on the right and stuff this into
  225.         // our menu placement.
  226.         
  227.     GetDialogItemAsControl( dialog, kBevelMenuOnRightCheck, &tempControl );
  228.     if ( GetControlValue( tempControl ) == 1 )
  229.         menuPlacement = kControlBevelButtonMenuOnRight;
  230.     else
  231.         menuPlacement = kControlBevelButtonMenuOnBottom;
  232.     
  233.         // Calculate the size of our button
  234.         
  235.     GetDialogItem( dialog, kBevelHeightText, &type, &handle, &rect );
  236.     GetDialogItemText( handle, text );
  237.     StringToNum( text, &temp );
  238.     bounds.bottom = temp;
  239.     GetDialogItem( dialog, kBevelWidthText, &type, &handle, &rect );
  240.     GetDialogItemText( handle, text );
  241.     StringToNum( text, &temp );
  242.     bounds.right = temp;
  243.     
  244.         // Get the text alignment, offset, and placement
  245.     
  246.     GetDialogItemAsControl( dialog, kBevelTextAlignPopup, &tempControl );
  247.     switch ( GetControlValue( tempControl ) )
  248.     {
  249.         case kTextSysDir:    alignment = kControlBevelButtonAlignTextSysDirection;    break;
  250.         case kTextLeft:        alignment = kControlBevelButtonAlignTextFlushLeft;        break;
  251.         case kTextRight:        alignment = kControlBevelButtonAlignTextFlushRight;        break;
  252.         case kTextCenter:    alignment = kControlBevelButtonAlignTextCenter;            break;
  253.     }
  254.     
  255.     GetDialogItem( dialog, kBevelTextOffsetText, &type, &handle, &rect );
  256.     GetDialogItemText( handle, text );
  257.     StringToNum( text, &longOffset );
  258.     offset = longOffset;
  259.  
  260.     GetDialogItemAsControl( dialog, kBevelTextPlacePopup, &tempControl );
  261.     switch ( GetControlValue( tempControl ) )
  262.     {
  263.         case kPlaceNormal:    placement = kControlBevelButtonPlaceNormally;            break;
  264.         case kPlaceLeft:        placement = kControlBevelButtonPlaceToLeftOfGraphic;    break;
  265.         case kPlaceRight:    placement = kControlBevelButtonPlaceToRightOfGraphic;    break;
  266.         case kPlaceAbove:    placement = kControlBevelButtonPlaceAboveGraphic;        break;
  267.         case kPlaceBelow:    placement = kControlBevelButtonPlaceBelowGraphic;        break;
  268.         case kPlaceSys:        placement = kControlBevelButtonPlaceSysDirection;        break;
  269.     }
  270.  
  271.         // Get the graphic alignment and offsets
  272.             
  273.     GetDialogItemAsControl( dialog, kBevelGraphicAlignPopup, &tempControl );
  274.     switch ( GetControlValue( tempControl ) )
  275.     {
  276.         case kGraphicSysDir:        graphicAlign = kControlBevelButtonAlignSysDirection;    break;
  277.         case kGraphicCenter:        graphicAlign = kControlBevelButtonAlignCenter;            break;
  278.         case kGraphicLeft:        graphicAlign = kControlBevelButtonAlignLeft;            break;
  279.         case kGraphicRight:        graphicAlign = kControlBevelButtonAlignRight;            break;
  280.         case kGraphicTop:        graphicAlign = kControlBevelButtonAlignTop;                break;
  281.         case kGraphicBottom:        graphicAlign = kControlBevelButtonAlignBottom;            break;
  282.         case kGraphicTopLeft:    graphicAlign = kControlBevelButtonAlignTopLeft;            break;
  283.         case kGraphicBotLeft:    graphicAlign = kControlBevelButtonAlignBottomLeft;        break;
  284.         case kGraphicTopRight:    graphicAlign = kControlBevelButtonAlignTopRight;        break;
  285.         case kGraphicBotRight:    graphicAlign = kControlBevelButtonAlignBottomRight;        break;
  286.     }
  287.  
  288.     GetDialogItem( dialog, kBevelGraphicHOffsetText, &type, &handle, &rect );
  289.     GetDialogItemText( handle, text );
  290.     StringToNum( text, &longOffset );
  291.     graphicOffset.h = longOffset;
  292.     GetDialogItem( dialog, kBevelGraphicVOffsetText, &type, &handle, &rect );
  293.     GetDialogItemText( handle, text );
  294.     StringToNum( text, &longOffset );
  295.     graphicOffset.v = longOffset;
  296.     
  297.         // Get the title.
  298.         
  299.     GetDialogItem( dialog, kBevelTitleText, &type, &handle, &rect );
  300.     GetDialogItemText( handle, title );
  301.     
  302.     DisposeDialog( dialog );
  303.     
  304.     CreateBevelButtonControl( window, &bounds, title, thickness, behavior, &content,
  305.         menuID, menuBehavior, menuPlacement, &control );
  306.     if ( control == nil ) return nil;
  307.     
  308.     SetControlVisibility( control, false, false );
  309.  
  310.     SetControlData( control, 0, kControlBevelButtonTextPlaceTag, sizeof( ControlButtonTextPlacement ),
  311.         (Ptr)&placement );
  312.         
  313.     SetControlData( control, 0, kControlBevelButtonTextAlignTag, sizeof( ControlButtonTextAlignment ),
  314.         (Ptr)&alignment );
  315.  
  316.     SetControlData( control, 0, kControlBevelButtonGraphicAlignTag, sizeof( ControlButtonGraphicAlignment ),
  317.         (Ptr)&graphicAlign );
  318.  
  319.     SetControlData( control, 0, kControlBevelButtonTextOffsetTag, sizeof( SInt16 ), (Ptr)&offset );
  320.     SetControlData( control, 0, kControlBevelButtonGraphicOffsetTag, sizeof( Point ), (Ptr)&graphicOffset );
  321.         
  322.     return control;
  323. }
  324.  
  325.  
  326. static pascal void
  327. UserPaneDrawProc (ControlHandle theControl, SInt16 thePart)
  328. {
  329.     #pragma unused( thePart )
  330.     Rect        bounds;
  331.     
  332.     GetControlBounds( theControl, &bounds );
  333.     
  334.     FrameRect( &bounds );
  335. }
  336.  
  337.  
  338. /***
  339.     This is just a very simplistic User Pane that that draws a rectangle around its frame, and 
  340.     returns an incrementing number for the part codes.  It shows how to set up a few of the 
  341.     various procedures needed for User Panes.
  342. ***/
  343. ControlHandle
  344. CreateUserPane( WindowPtr window )
  345. {
  346.     Rect        bounds = { 0, 0, 100, 100 };
  347.     ControlHandle theControl;
  348.     
  349.     CreateUserPaneControl( window, &bounds, 0, &theControl );
  350.     if (theControl)
  351.         {
  352.             ControlUserPaneDrawUPP myPaneDrawProc;
  353.             
  354.             SetControlVisibility( theControl, false, false );
  355.             myPaneDrawProc = NewControlUserPaneDrawProc(UserPaneDrawProc);
  356.             SetControlData(theControl, 0, kControlUserPaneDrawProcTag, sizeof(ControlUserPaneDrawUPP), (Ptr) &myPaneDrawProc);
  357.  
  358.             return(theControl);
  359.         }
  360.         
  361.     return(nil);
  362. }
  363.  
  364.  
  365. ControlHandle
  366. CreateChasingArrows( WindowPtr window )
  367. {
  368.     Rect        bounds = { 0, 0, 16, 16 };
  369.     ControlRef    control;
  370.  
  371.     CreateChasingArrowsControl( window, &bounds, &control );
  372.  
  373.     if ( control != nil )
  374.         SetControlVisibility( control, false, false );
  375.     
  376.     return control;
  377. }
  378.  
  379. ControlHandle
  380. CreateDivider( WindowPtr window )
  381. {
  382.     DialogPtr        dialog;
  383.     SInt16            itemHit = 0;
  384.     ControlHandle    control = nil;
  385.     SInt16            type;
  386.     Handle            handle;
  387.     Rect            rect;
  388.     SInt32            length;
  389.     Str255            text;
  390.     Rect            bounds = { 0, 0, 4, 4 };
  391.     ControlHandle    tempControl;
  392.     
  393.     dialog = GetNewDialog( 2001, nil, (WindowPtr)-1L );
  394.     if ( dialog == nil ) return nil;
  395.  
  396.     SetDialogDefaultItem( dialog, kDividerOKButton );
  397.     SetDialogCancelItem( dialog, kDividerCancelButton );
  398.         
  399.     while ( itemHit != kDividerCancelButton && itemHit != kDividerOKButton )
  400.     {
  401.         ModalDialog( nil, &itemHit );
  402.     }
  403.     
  404.     if ( itemHit == kDividerCancelButton )
  405.     {
  406.         DisposeDialog( dialog );
  407.         return nil;
  408.     }
  409.     
  410.     GetDialogItem( dialog, kLengthText, &type, &handle, &rect );
  411.     GetDialogItemText( handle, text );
  412.     StringToNum( text, &length );
  413.     
  414.     GetDialogItemAsControl( dialog, kDividerRadioGroup, &tempControl );
  415.     if ( GetControlValue( tempControl ) == 1 )
  416.         bounds.right = bounds.left + length;
  417.     else
  418.         bounds.bottom = bounds.top + length;
  419.     
  420.     DisposeDialog( dialog );
  421.     
  422.     CreateSeparatorControl( window, &bounds, &control );
  423.     if ( control != nil )
  424.         SetControlVisibility( control, false, false );
  425.     
  426.     return control;
  427. }
  428.  
  429. ControlHandle
  430. CreateTriangle( WindowPtr window )
  431. {
  432.     DialogPtr                                dialog;
  433.     SInt16                                    itemHit = 0;
  434.     ControlHandle                            control = nil;
  435.     Rect                                    bounds = { 0, 0, 12, 12 };
  436.     ControlDisclosureTriangleOrientation    orientation;
  437.     Boolean                                    autoToggles;
  438.     ControlHandle                            tempControl;
  439.     
  440.     dialog = GetNewDialog( 2002, nil, (WindowPtr)-1L );
  441.     if ( dialog == nil ) return nil;
  442.  
  443.     SetDialogDefaultItem( dialog, kTriangleOKButton );
  444.     SetDialogCancelItem( dialog, kTriangleCancelButton );
  445.         
  446.     while ( itemHit != kTriangleCancelButton && itemHit != kTriangleOKButton )
  447.     {
  448.         ModalDialog( nil, &itemHit );
  449.         
  450.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  451.         switch ( itemHit )
  452.         {
  453.             case kLeftFacingCheck:
  454.             case kAutoTrackCheck:
  455.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  456.                 break;
  457.         }
  458.     }
  459.     
  460.     if ( itemHit == kTriangleCancelButton )
  461.     {
  462.         DisposeDialog( dialog );
  463.         return nil;
  464.     }
  465.     
  466.     GetDialogItemAsControl( dialog, kLeftFacingCheck, &tempControl );
  467.     if ( GetControlValue( tempControl ) == 1 )
  468.         orientation = kControlDisclosureTrianglePointLeft;
  469.     else
  470.         orientation = kControlDisclosureTrianglePointRight;
  471.         
  472.     GetDialogItemAsControl( dialog, kAutoTrackCheck, &tempControl );
  473.     if ( GetControlValue( tempControl ) == 1 )
  474.         autoToggles = true;
  475.     else
  476.         autoToggles = false;
  477.     
  478.     DisposeDialog( dialog );
  479.     
  480.     CreateDisclosureTriangleControl( window, &bounds, orientation, "\pTriangle",
  481.         false, autoToggles, &control );
  482.     if ( control != nil )
  483.         SetControlVisibility( control, false, false );
  484.     
  485.     return control;
  486. }
  487.  
  488. ControlHandle
  489. CreateEditText( WindowPtr window )
  490. {
  491.     DialogPtr        dialog;
  492.     SInt16            itemHit = 0;
  493.     ControlHandle    control = nil;
  494.     Rect            bounds = { 20, 20, 36, 200 };
  495.     Boolean            isPassword;
  496.     ControlHandle    tempControl;
  497.     unsigned char *string = "\pSample Text";
  498.     
  499.     dialog = GetNewDialog( 2014, nil, (WindowPtr)-1L );
  500.     if ( dialog == nil ) return nil;
  501.  
  502.     SetDialogDefaultItem( dialog, kETOKButton );
  503.     SetDialogCancelItem( dialog, kETCancelButton );
  504.         
  505.     while ( itemHit != kETCancelButton && itemHit != kETOKButton )
  506.     {
  507.         ModalDialog( nil, &itemHit );
  508.         
  509.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  510.         if (itemHit == kETPasswordCheck)
  511.             SetControlValue(tempControl, !GetControlValue(tempControl));
  512.     }
  513.     
  514.     if ( itemHit == kETCancelButton )
  515.     {
  516.         DisposeDialog( dialog );
  517.         return nil;
  518.     }
  519.     
  520.     GetDialogItemAsControl( dialog, kETPasswordCheck, &tempControl );
  521.     if (GetControlValue( tempControl ))
  522.         isPassword = true;
  523.     else
  524.         isPassword = false;
  525.  
  526.     DisposeDialog( dialog );
  527.     
  528.     CreateEditTextControl( window, &bounds, "\p", isPassword, false, nil, &control );
  529.     if (!control) return nil;
  530.     
  531.     SetControlVisibility( control, false, false );
  532.  
  533.     SetKeyboardFocus(window, control, kControlFocusNextPart);
  534.     
  535.     if (! isPassword)
  536.         SetControlData(control,kControlNoPart,kControlEditTextTextTag,*string,(Ptr) string + 1);
  537.     
  538.     return control;
  539. }
  540.  
  541. ControlHandle
  542. CreateSlider( WindowPtr window )
  543. {
  544.     DialogPtr                    dialog;
  545.     SInt16                        itemHit = 0;
  546.     ControlHandle                dialogControl,tempControl;
  547.     ControlSliderOrientation        orientation;
  548.     UInt16                        numTickMarks;
  549.     ControlRef                    control;
  550.     Rect                        bounds = { 20, 20, 80, 200 };
  551.     Boolean                         enableItems,alreadyEnabled;
  552.     
  553.     dialog = GetNewDialog( 2016, nil, (WindowPtr)-1L );
  554.     if ( dialog == nil ) return nil;
  555.  
  556.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  557.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  558.     GetDialogItemAsControl(dialog, kSliderDirectional, &tempControl);
  559.     SetControlValue(tempControl, 1);
  560.     ShowWindow( GetDialogWindow( dialog ) );
  561.         
  562.     while ( itemHit != kStdOkItemIndex && itemHit != kStdCancelItemIndex )
  563.         {
  564.             ModalDialog( nil, &itemHit );
  565.             
  566.             GetDialogItemAsControl(dialog, itemHit, &dialogControl);
  567.             
  568.             if ((itemHit == kSliderTickMarks) || (itemHit == kSliderReverse))
  569.                 SetControlValue(dialogControl, !GetControlValue(dialogControl)); // toggle checkbox
  570.  
  571.             if ((itemHit == kSliderNonDirectional) || (itemHit == kSliderDirectional))
  572.                 {
  573.                     alreadyEnabled = GetControlValue(dialogControl);
  574.                     
  575.                     SetControlValue(dialogControl, 1);
  576.                     GetDialogItemAsControl(dialog, (itemHit == kSliderNonDirectional) ? kSliderDirectional : kSliderNonDirectional, &tempControl);
  577.                     SetControlValue(tempControl, 0);
  578.                     
  579.                     enableItems = (itemHit == kSliderDirectional);
  580.                     
  581.                     if (!alreadyEnabled) // don't enable/disable sub-items every time, it flickers
  582.                         {
  583.                             GetDialogItemAsControl(dialog, kSliderTickMarks, &tempControl);
  584.                             HiliteControl(tempControl, enableItems ? 0 : kControlDisabledPart);
  585.                             GetDialogItemAsControl(dialog, kSliderReverse, &tempControl);
  586.                             HiliteControl(tempControl, enableItems ? 0 : kControlDisabledPart);
  587.                         }
  588.                 }
  589.         }
  590.  
  591.     if ( itemHit == kStdCancelItemIndex )
  592.     {
  593.         DisposeDialog( dialog );
  594.         return nil;
  595.     }
  596.     
  597.     GetDialogItemAsControl(dialog, kSliderNonDirectional, &tempControl);
  598.  
  599.     if (GetControlValue(tempControl))
  600.     {
  601.         orientation = kControlSliderDoesNotPoint;
  602.         numTickMarks = 0;
  603.     }
  604.     else
  605.     {
  606.         GetDialogItemAsControl(dialog, kSliderTickMarks, &tempControl);
  607.  
  608.         if (GetControlValue(tempControl))
  609.             numTickMarks = 5;
  610.         else
  611.             numTickMarks = 0;
  612.  
  613.         GetDialogItemAsControl(dialog, kSliderReverse, &tempControl);
  614.  
  615.         if (GetControlValue(tempControl))
  616.             orientation = kControlSliderPointsUpOrLeft;
  617.         else
  618.             orientation = kControlSliderPointsDownOrRight;
  619.     }
  620.  
  621.     DisposeDialog( dialog );
  622.     
  623.     CreateSliderControl( window, &bounds, 0, 0, 100, orientation, numTickMarks, false, nil, &control );
  624.     if ( control != nil )
  625.         SetControlVisibility( control, false, false );
  626.  
  627.     return control;
  628. }
  629.  
  630. ControlHandle
  631. CreateClock( WindowPtr window )
  632. {
  633.     DialogPtr            dialog;
  634.     SInt16                itemHit = 0;
  635.     ControlHandle        control = nil,dialogControl,tempControl;
  636.     Rect                bounds = { 0, 0, 23, 125 };
  637.     ControlClockType        clockTypes[4] = {kControlClockTypeHourMinute, kControlClockTypeHourMinuteSecond, kControlClockTypeMonthDay, kControlClockTypeMonthDayYear};
  638.     short                itemIndex,kindIndex=0;
  639.     
  640.     dialog = GetNewDialog( 2017, nil, (WindowPtr)-1L );
  641.     if ( dialog == nil ) return nil;
  642.  
  643.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  644.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  645.     GetDialogItemAsControl(dialog, kClockTime, &tempControl);
  646.     SetControlValue(tempControl, 1);
  647.     ShowWindow( GetDialogWindow( dialog ) );
  648.         
  649.     while ((itemHit != kStdOkItemIndex) && (itemHit != kStdCancelItemIndex))
  650.         {
  651.             ModalDialog( nil, &itemHit );
  652.             
  653.             GetDialogItemAsControl(dialog, itemHit, &dialogControl);
  654.             
  655.             if ((itemHit >= kClockTime) && (itemHit <= kClockMonthYear) && !GetControlValue(dialogControl)) 
  656.             // if it's radio buttons and the radio button isn't already selected
  657.                 {
  658.                     for(itemIndex=kClockTime;itemIndex<=kClockMonthYear;itemIndex++)
  659.                         {
  660.                             GetDialogItemAsControl(dialog, itemIndex, &tempControl);
  661.                         
  662.                             if (itemIndex == itemHit)
  663.                                 SetControlValue(tempControl, 1);
  664.                             else
  665.                                 SetControlValue(tempControl, 0);
  666.                         }
  667.                 }
  668.                         
  669.         }
  670.  
  671.     if ( itemHit == kStdCancelItemIndex )
  672.     {
  673.         DisposeDialog( dialog );
  674.         return nil;
  675.     }
  676.  
  677.     for(itemIndex=kClockTime;itemIndex<=kClockMonthYear;itemIndex++)
  678.     {    
  679.         GetDialogItemAsControl(dialog, itemIndex, &tempControl);
  680.         
  681.         if (GetControlValue(tempControl))
  682.             kindIndex = itemIndex - kClockTime;
  683.     }
  684.  
  685.     DisposeDialog( dialog );
  686.  
  687.     CreateClockControl( window, &bounds, clockTypes[kindIndex], kControlClockNoFlags, &control );
  688.  
  689.     if ( control == nil )
  690.         return nil;
  691.  
  692.     SetControlVisibility( control, false, false );
  693.  
  694.     SetKeyboardFocus(window, control, kControlFocusNextPart);
  695.     
  696.     return(control);
  697. }
  698.  
  699. ControlHandle
  700. CreateStaticText( WindowPtr window )
  701. {
  702.     DialogPtr        dialog;
  703.     SInt16            itemHit = 0;
  704.     ControlHandle    control = nil;
  705.     Rect            bounds = { 20, 20, 52, 200 };
  706.     DialogItemType    dummyType;
  707.     Handle            textItem;
  708.     Rect            dummyRect;
  709.     Str255            text;
  710.     
  711.     dialog = GetNewDialog( 2015, nil, (WindowPtr)-1L );
  712.     if ( dialog == nil ) return nil;
  713.  
  714.     SetDialogDefaultItem( dialog, kSTOKButton );
  715.     SetDialogCancelItem( dialog, kSTCancelButton );
  716.         
  717.     while ( itemHit != kSTCancelButton && itemHit != kSTOKButton )
  718.         ModalDialog( nil, &itemHit );
  719.         
  720.  
  721.     if ( itemHit == kSTCancelButton )
  722.     {
  723.         DisposeDialog( dialog );
  724.         return nil;
  725.     }
  726.     
  727.     GetDialogItem(dialog, 3, &dummyType, &textItem, &dummyRect);
  728.     
  729.     GetDialogItemText(textItem, text);
  730.  
  731.     DisposeDialog( dialog );
  732.     
  733.     CreateStaticTextControl( window, &bounds, "\p", nil, &control );
  734.     
  735.     if (!control)
  736.         return(nil);
  737.  
  738.     SetControlVisibility( control, false, false );
  739.     
  740.     SetControlData(control, kControlNoPart, kControlStaticTextTextTag, *text, (Ptr) &(text[1]));
  741.  
  742.     return(control);
  743. }
  744.  
  745.  
  746.  
  747. ControlHandle
  748. CreateFinderHeader( WindowPtr window )
  749. {
  750.     DialogPtr        dialog;
  751.     SInt16            itemHit = 0;
  752.     ControlHandle    control = nil;
  753.     SInt16            type;
  754.     Handle            handle;
  755.     Rect            rect;
  756.     Rect            bounds = { 0, 0, 0, 0 };
  757.     Boolean            isListHeader;
  758.     Str255            text;
  759.     SInt32            number;
  760.     ControlHandle    tempControl;
  761.     
  762.     dialog = GetNewDialog( 2003, nil, (WindowPtr)-1L );
  763.     if ( dialog == nil ) return nil;
  764.  
  765.     SetDialogDefaultItem( dialog, kFHOKButton );
  766.     SetDialogCancelItem( dialog, kFHCancelButton );
  767.         
  768.     while ( itemHit != kFHCancelButton && itemHit != kFHOKButton )
  769.     {
  770.         ModalDialog( nil, &itemHit );
  771.         
  772.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  773.         switch ( itemHit )
  774.         {
  775.             case kFHListViewCheck:
  776.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  777.                 break;
  778.         }
  779.     }
  780.     
  781.     if ( itemHit == kFHCancelButton )
  782.     {
  783.         DisposeDialog( dialog );
  784.         return nil;
  785.     }
  786.     
  787.     isListHeader = false;
  788.     GetDialogItemAsControl( dialog, kFHListViewCheck, &tempControl );
  789.     if ( GetControlValue( tempControl ) == 1 )
  790.         isListHeader = true;;
  791.  
  792.     GetDialogItem( dialog, kFHHeightText, &type, &handle, &rect );
  793.     GetDialogItemText( handle, text );
  794.     StringToNum( text, &number );
  795.     bounds.bottom = number;
  796.     
  797.     GetDialogItem( dialog, kFHWidthText, &type, &handle, &rect );
  798.     GetDialogItemText( handle, text );
  799.     StringToNum( text, &number );
  800.     bounds.right = number;
  801.     
  802.     DisposeDialog( dialog );
  803.     
  804.     CreateWindowHeaderControl( window, &bounds, isListHeader, &control );
  805.     if ( control == nil ) return nil;
  806.  
  807.     SetControlVisibility( control, false, false );
  808.     
  809.     return control;
  810. }
  811.  
  812. ControlHandle
  813. CreateIconCDEF( WindowPtr window )
  814. {
  815.     return CreatePictureOrIconCDEF( window, false );
  816. }
  817.  
  818. ControlHandle
  819. CreatePictureCDEF( WindowPtr window )
  820. {
  821.     return CreatePictureOrIconCDEF( window, true );
  822. }
  823.  
  824. static ControlHandle
  825. CreatePictureOrIconCDEF( WindowPtr window, Boolean isPicture )
  826. {
  827.     DialogPtr            dialog;
  828.     SInt16                itemNo;
  829.     SInt16                type;
  830.     Handle                handle;
  831.     Rect                rect;
  832.     Str255                text;
  833.     SInt32                resID, height, width;
  834.     Boolean                dontTrack = false;
  835.     Rect                bounds = { 0, 0, 0, 0 };
  836.     ControlKeyFilterUPP    filterProc;
  837.     ControlRef            tempControl;
  838.     ControlRef            control;
  839.     
  840.     dialog = GetNewDialog( 2005, nil, (WindowPtr)-1L );
  841.     if ( dialog == nil ) return nil;
  842.     
  843.     if ( ! isPicture )
  844.         SetWTitle( GetDialogWindow( dialog ), "\pIcon CDEF" );
  845.     else
  846.         SetWTitle( GetDialogWindow( dialog ), "\pPicture CDEF" );
  847.         
  848.     SetDialogDefaultItem( dialog, kIconOK );
  849.     SetDialogCancelItem( dialog, kIconCancel );
  850.     
  851.     filterProc = NewControlKeyFilterProc( NumericFilter );
  852.     GetDialogItemAsControl( dialog, kIconResIDText, &tempControl );
  853.     SetEditTextKeyFilter( tempControl, filterProc );
  854.     GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
  855.     SetEditTextKeyFilter( tempControl, filterProc );
  856.     GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
  857.     SetEditTextKeyFilter( tempControl, filterProc );
  858.                     
  859.     ShowWindow( GetDialogWindow( dialog ) );
  860.                     
  861.     while( itemNo != kIconCancel && itemNo != kIconOK )
  862.     {
  863.         ModalDialog( nil, &itemNo );
  864.  
  865.         GetDialogItemAsControl( dialog, itemNo, &tempControl );
  866.         switch ( itemNo )
  867.         {
  868.             case kIconNoHitCheck:
  869.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  870.                 break;
  871.  
  872.             case kIconUseRectCheck:
  873.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  874.                 if ( GetControlValue( tempControl ) == 1 )
  875.                 {
  876.                     GetDialogItemAsControl( dialog, kIconHeightLabelText, &tempControl );
  877.                     DeactivateControl( tempControl );
  878.                     GetDialogItemAsControl( dialog, kIconWidthLabelText, &tempControl );
  879.                     DeactivateControl( tempControl );
  880.                     GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
  881.                     DeactivateControl( tempControl );
  882.                     GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
  883.                     DeactivateControl( tempControl );
  884.                 }
  885.                 else
  886.                 {
  887.                     GetDialogItemAsControl( dialog, kIconHeightLabelText, &tempControl );
  888.                     ActivateControl( tempControl );
  889.                     GetDialogItemAsControl( dialog, kIconWidthLabelText, &tempControl );
  890.                     ActivateControl( tempControl );
  891.                     GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
  892.                     ActivateControl( tempControl );
  893.                     GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
  894.                     ActivateControl( tempControl );
  895.                 }
  896.                 break;
  897.         }
  898.     }
  899.     DisposeControlKeyFilterUPP( filterProc );
  900.  
  901.     if ( itemNo == kIconCancel )
  902.     {
  903.         DisposeDialog( dialog );
  904.         return nil;
  905.     }
  906.  
  907.     GetDialogItem( dialog, kIconResIDText, &type, &handle, &rect );
  908.     GetDialogItemText( handle, text );
  909.     StringToNum( text, &resID );
  910.     
  911.     GetDialogItemAsControl( dialog, kIconUseRectCheck, &tempControl );
  912.     if ( GetControlValue( tempControl ) == 1 )
  913.     {
  914.         if ( isPicture )
  915.             GetPictureSize( resID, &height, &width );
  916.         else
  917.             GetIconSize( resID, &height, &width );
  918.     }
  919.     else
  920.     {
  921.         GetDialogItem( dialog, kIconHeightText, &type, &handle, &rect );
  922.         GetDialogItemText( handle, text );
  923.         StringToNum( text, &height );
  924.         
  925.         GetDialogItem( dialog, kIconWidthText, &type, &handle, &rect );
  926.         GetDialogItemText( handle, text );
  927.         StringToNum( text, &width );
  928.     }    
  929.     GetDialogItemAsControl( dialog, kIconNoHitCheck, &tempControl );
  930.     if ( GetControlValue( tempControl ) == 1 )
  931.         dontTrack = true;
  932.     
  933.     DisposeDialog( dialog );
  934.     
  935.     bounds.bottom = bounds.top + height;
  936.     bounds.right = bounds.left + width;
  937.  
  938.     if ( isPicture )
  939.     {
  940.         ControlButtonContentInfo        content;
  941.  
  942.            content.contentType = kControlNoContent;
  943.         if ( resID != 0 )
  944.         {
  945.             content.contentType = kControlContentPictRes;
  946.             content.u.resID = resID;
  947.         }
  948.  
  949.         CreatePictureControl( window, &bounds, &content, dontTrack, &control );
  950.     }
  951.     else
  952.     {
  953.         ControlButtonContentInfo        content;
  954.         
  955.         content.contentType = kControlNoContent;
  956.         if ( resID != 0 )
  957.         {
  958.             content.contentType = kControlContentICONRes;
  959.             content.u.resID = resID;
  960.         }
  961.  
  962.         CreateIconControl( window, &bounds, &content, dontTrack, &control );
  963.     }
  964.  
  965.     if ( control != nil )
  966.         SetControlVisibility( control, false, false );
  967.  
  968.     return control;
  969. }
  970.  
  971. ControlHandle
  972. CreateProgressBar( WindowPtr window )
  973. {
  974.     DialogPtr        dialog;
  975.     SInt16            itemHit = 0;
  976.     ControlHandle    control = nil;
  977.     SInt16            type;
  978.     Handle            handle;
  979.     Rect            rect;
  980.     Rect            bounds = { 0, 0, 16, 0 };
  981.     Str255            text;
  982.     SInt32            number;
  983.     Boolean            indeterminate;
  984.     ControlHandle    tempControl;
  985.     
  986.     dialog = GetNewDialog( 2006, nil, (WindowPtr)-1L );
  987.     if ( dialog == nil ) return nil;
  988.  
  989.     SetDialogDefaultItem( dialog, kProgOKButton );
  990.     SetDialogCancelItem( dialog, kProgCancelButton );
  991.         
  992.     while ( itemHit != kProgCancelButton && itemHit != kProgOKButton )
  993.     {
  994.         ModalDialog( nil, &itemHit );
  995.         
  996.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  997.         switch ( itemHit )
  998.         {
  999.             case kProgIndeterminateCheck:
  1000.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  1001.                 break;
  1002.         }
  1003.     }
  1004.     
  1005.     if ( itemHit == kProgCancelButton )
  1006.     {
  1007.         DisposeDialog( dialog );
  1008.         return nil;
  1009.     }
  1010.     
  1011.     GetDialogItemAsControl( dialog, kProgIndeterminateCheck, &tempControl );
  1012.     indeterminate = ( GetControlValue( tempControl ) == 1 );
  1013.  
  1014.     GetDialogItem( dialog, kProgLengthText, &type, &handle, &rect );
  1015.     GetDialogItemText( handle, text );
  1016.     StringToNum( text, &number );
  1017.     bounds.right = number;
  1018.     
  1019.     DisposeDialog( dialog );
  1020.     
  1021.     CreateProgressBarControl( window, &bounds, 50, 0, 100, indeterminate, &control );
  1022.     if ( control == nil ) return nil;
  1023.  
  1024.     SetControlVisibility( control, false, false );    
  1025.         
  1026.     return control;
  1027. }
  1028.  
  1029. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1030. //    Ä CreateLittleArrows                                                    PUBLIC
  1031. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1032. //    Creates the little arrows CDEF. We just use a standard size - no options.
  1033. //
  1034. ControlHandle
  1035. CreateLittleArrows( WindowPtr window )
  1036. {
  1037.     Rect        bounds = { 0, 0, 24, 13 };
  1038.     ControlRef    control;
  1039.  
  1040.     CreateLittleArrowsControl( window, &bounds, 0, 0, 100, 1, &control );
  1041.  
  1042.     if ( control != nil )
  1043.         SetControlVisibility( control, false, false );
  1044.  
  1045.     return control;
  1046. }
  1047.  
  1048. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1049. //    Ä CreateGroupBox                                                            PUBLIC
  1050. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1051. //    Creates a group box.
  1052. //
  1053. ControlHandle
  1054. CreateGroupBox( WindowPtr window )
  1055. {
  1056.     enum { kPrimary, kSecondary };
  1057.     enum { kText = 1, kCheckBox, kPopup };
  1058.     
  1059.     DialogPtr                dialog;
  1060.     SInt16                    itemHit = 0;
  1061.     SInt16                    type;
  1062.     Handle                    handle;
  1063.     Rect                    rect;
  1064.     Rect                    bounds = { 0, 0, 16, 0 };
  1065.     ControlKeyFilterUPP        filterProc;
  1066.     Str255                    text, title;
  1067.     SInt32                    height, width;
  1068.     ControlRef                tempControl;
  1069.     Boolean                    isPrimary;
  1070.     SInt32                    menuID;
  1071.     ControlRef                control = nil;
  1072.     
  1073.     dialog = GetNewDialog( 2007, nil, (WindowPtr)-1L );
  1074.     if ( dialog == nil ) return nil;
  1075.  
  1076.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1077.  
  1078.     GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
  1079.     DeactivateControl( tempControl );
  1080.     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  1081.     DeactivateControl( tempControl );
  1082.  
  1083.     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  1084.     SetEditTextKeyFilter( tempControl, filterProc );
  1085.     GetDialogItemAsControl( dialog, kGroupHeightText, &tempControl );
  1086.     SetEditTextKeyFilter( tempControl, filterProc );
  1087.     GetDialogItemAsControl( dialog, kGroupWidthText, &tempControl );
  1088.     SetEditTextKeyFilter( tempControl, filterProc );
  1089.  
  1090.     SetDialogDefaultItem( dialog, kGroupOKButton );
  1091.     SetDialogCancelItem( dialog, kGroupCancelButton );
  1092.     
  1093.     while ( itemHit != kGroupCancelButton && itemHit != kGroupOKButton )
  1094.     {
  1095.         ModalDialog( nil, &itemHit );
  1096.         
  1097.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  1098.         switch ( itemHit )
  1099.         {
  1100.             case kGroupVariantPopup:
  1101.                 if ( GetControlValue( tempControl ) == kPopup )
  1102.                 {
  1103.                     GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
  1104.                     ActivateControl( tempControl );
  1105.                     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  1106.                     ActivateControl( tempControl );
  1107.                 }
  1108.                 else
  1109.                 {
  1110.                     GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
  1111.                     DeactivateControl( tempControl );
  1112.                     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  1113.                     DeactivateControl( tempControl );
  1114.                 }
  1115.         }
  1116.     }
  1117.     DisposeControlKeyFilterUPP( filterProc );
  1118.     
  1119.     if ( itemHit == kGroupCancelButton )
  1120.     {
  1121.         DisposeDialog( dialog );
  1122.         return nil;
  1123.     }
  1124.     
  1125.         // Are we primary or secondary?
  1126.         
  1127.     isPrimary = true;
  1128.     GetDialogItemAsControl( dialog, kGroupRadioGroup, &tempControl );
  1129.     if ( GetControlValue( tempControl ) == 2 )
  1130.         isPrimary = false;
  1131.     
  1132.         // Calculate the bounding rectangle based on width/height
  1133.         
  1134.     GetDialogItem( dialog, kGroupHeightText, &type, &handle, &rect );
  1135.     GetDialogItemText( handle, text );
  1136.     StringToNum( text, &height );
  1137.     GetDialogItem( dialog, kGroupWidthText, &type, &handle, &rect );
  1138.     GetDialogItemText( handle, text );
  1139.     StringToNum( text, &width );
  1140.  
  1141.     bounds.bottom = height;
  1142.     bounds.right = width;
  1143.     
  1144.         // Get the title of the control
  1145.         
  1146.     GetDialogItem( dialog, kGroupTitleText, &type, &handle, &rect );
  1147.     GetDialogItemText( handle, title );
  1148.     
  1149.     GetDialogItemAsControl( dialog, kGroupVariantPopup, &tempControl );
  1150.     switch ( GetControlValue( tempControl ) )
  1151.     {
  1152.         case kCheckBox:
  1153.             CreateCheckGroupBoxControl( window, &bounds, title, isPrimary, false, &control );
  1154.             break;
  1155.         
  1156.         case kPopup:
  1157.             // get the menu
  1158.             GetDialogItem( dialog, kGroupMenuIDText, &type, &handle, &rect );
  1159.             GetDialogItemText( handle, text );
  1160.             StringToNum( text, &menuID );
  1161.  
  1162.             CreatePopupGroupBoxControl( window, &bounds, title, isPrimary, menuID,
  1163.                 true, 0, 0, 0, &control );
  1164.             break;
  1165.  
  1166.         case kText:
  1167.             CreateGroupBoxControl( window, &bounds, title, isPrimary, &control );
  1168.             break;
  1169.     }            
  1170.     DisposeDialog( dialog );
  1171.  
  1172.     if ( control != nil )
  1173.         SetControlVisibility( control, false, false );
  1174.  
  1175.     return control;
  1176. }
  1177.  
  1178. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1179. //    Ä CreatePlacard                                                            PUBLIC
  1180. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1181. //    This routine creates a placard in any size the user wants.
  1182. //
  1183. ControlHandle
  1184. CreatePlacard( WindowPtr window )
  1185. {
  1186.     DialogPtr            dialog;
  1187.     SInt16                itemHit = 0;
  1188.     ControlHandle        control = nil;
  1189.     SInt16                type;
  1190.     Handle                handle;
  1191.     Rect                rect;
  1192.     Rect                bounds = { 0, 0, 0, 0 };
  1193.     Str255                text;
  1194.     SInt32                number;
  1195.     ControlKeyFilterUPP    filterProc;
  1196.     ControlHandle        tempControl;
  1197.     
  1198.     dialog = GetNewDialog( 2008, nil, (WindowPtr)-1L );
  1199.     if ( dialog == nil ) return nil;
  1200.  
  1201.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1202.  
  1203.     GetDialogItemAsControl( dialog, kPlacardHeightText, &tempControl );
  1204.     SetEditTextKeyFilter( tempControl, filterProc );
  1205.     GetDialogItemAsControl( dialog, kPlacardWidthText, &tempControl );
  1206.     SetEditTextKeyFilter( tempControl, filterProc );
  1207.  
  1208.     SetDialogDefaultItem( dialog, kPlacardOKButton );
  1209.     SetDialogCancelItem( dialog, kPlacardCancelButton );
  1210.         
  1211.     while ( itemHit != kPlacardCancelButton && itemHit != kPlacardOKButton )
  1212.     {
  1213.         ModalDialog( nil, &itemHit );
  1214.     }
  1215.     DisposeControlKeyFilterUPP( filterProc );
  1216.     
  1217.     if ( itemHit == kPlacardCancelButton )
  1218.     {
  1219.         DisposeDialog( dialog );
  1220.         return nil;
  1221.     }
  1222.     
  1223.     GetDialogItem( dialog, kPlacardHeightText, &type, &handle, &rect );
  1224.     GetDialogItemText( handle, text );
  1225.     StringToNum( text, &number );
  1226.     bounds.bottom = number;
  1227.     
  1228.     GetDialogItem( dialog, kPlacardWidthText, &type, &handle, &rect );
  1229.     GetDialogItemText( handle, text );
  1230.     StringToNum( text, &number );
  1231.     bounds.right = number;
  1232.     
  1233.     DisposeDialog( dialog );
  1234.     
  1235.     CreatePlacardControl( window, &bounds, &control );
  1236.     if ( control == nil ) return nil;
  1237.  
  1238.     SetControlVisibility( control, false, false );
  1239.     
  1240.     return control;
  1241. }
  1242.  
  1243. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1244. //    Ä CreatePopupArrow                                                        PUBLIC
  1245. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1246. //    This routine creates a popup arrow in any direction and size the user wants.
  1247. //
  1248. ControlHandle
  1249. CreatePopupArrow( WindowPtr window )
  1250. {
  1251.     enum { kEast = 1, kWest, kNorth, kSouth };
  1252.     
  1253.     DialogRef                        dialog;
  1254.     SInt16                            itemHit = 0;
  1255.     Rect                            bounds = { 0, 0, 50, 50 };
  1256.     ControlPopupArrowOrientation        orientation;
  1257.     ControlPopupArrowSize            size;
  1258.     ControlRef                        control;
  1259.     ControlRef                        tempControl;
  1260.     
  1261.     dialog = GetNewDialog( 2009, nil, (WindowPtr)-1L );
  1262.     if ( dialog == nil ) return nil;
  1263.  
  1264.     SetDialogDefaultItem( dialog, kPopArrowOKButton );
  1265.     SetDialogCancelItem( dialog, kPopArrowCancelButton );
  1266.         
  1267.     while ( itemHit != kPopArrowCancelButton && itemHit != kPopArrowOKButton )
  1268.     {
  1269.         ModalDialog( nil, &itemHit );
  1270.         
  1271.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  1272.         switch ( itemHit )
  1273.         {
  1274.             case kPopArrowSmallCheck:
  1275.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  1276.                 break;
  1277.         }
  1278.     }
  1279.     
  1280.     if ( itemHit == kPopArrowCancelButton )
  1281.     {
  1282.         DisposeDialog( dialog );
  1283.         return nil;
  1284.     }
  1285.  
  1286.     size = kControlPopupArrowSizeNormal;    
  1287.     GetDialogItemAsControl( dialog, kPopArrowSmallCheck, &tempControl );
  1288.     if ( GetControlValue( tempControl ) == 1 )
  1289.         size = kControlPopupArrowSizeSmall;
  1290.  
  1291.     GetDialogItemAsControl( dialog, kPopArrowDirPopup, &tempControl );
  1292.     switch ( GetControlValue( tempControl ) )
  1293.     {
  1294.         default:
  1295.         case kEast:        orientation = kControlPopupArrowOrientationEast;    break;
  1296.         case kWest:        orientation = kControlPopupArrowOrientationWest;    break;
  1297.         case kNorth:        orientation = kControlPopupArrowOrientationNorth;    break;
  1298.         case kSouth:        orientation = kControlPopupArrowOrientationSouth;    break;
  1299.     }
  1300.     
  1301.     DisposeDialog( dialog );
  1302.     
  1303.     CreatePopupArrowControl( window, &bounds, orientation, size, &control );
  1304.  
  1305.     if ( control != nil )
  1306.         SetControlVisibility( control, false, false );
  1307.  
  1308.     return control;
  1309. }
  1310.  
  1311. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1312. //    Ä CreateScrollBar                                                    PUBLIC
  1313. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1314. //    Creates a scroll bar.
  1315. //
  1316. ControlHandle
  1317. CreateScrollBar( WindowPtr window )
  1318. {
  1319.     DialogPtr        dialog;
  1320.     SInt16            itemHit = 0;
  1321.     SInt16            type;
  1322.     Handle            handle;
  1323.     Rect            rect;
  1324.     SInt32            length;
  1325.     Str255            text;
  1326.     Rect            bounds = { 0, 0, 16, 16 };
  1327.     ControlRef        tempControl;
  1328.     ControlRef        control;
  1329.     
  1330.     dialog = GetNewDialog( 2010, nil, (WindowPtr)-1L );
  1331.     if ( dialog == nil ) return nil;
  1332.  
  1333.     SetDialogDefaultItem( dialog, kScrollOKButton );
  1334.     SetDialogCancelItem( dialog, kScrollCancelButton );
  1335.         
  1336.     while ( itemHit != kScrollCancelButton && itemHit != kScrollOKButton )
  1337.     {
  1338.         ModalDialog( nil, &itemHit );
  1339.     }
  1340.     
  1341.     if ( itemHit == kScrollCancelButton )
  1342.     {
  1343.         DisposeDialog( dialog );
  1344.         return nil;
  1345.     }
  1346.     
  1347.     GetDialogItem( dialog, kScrollLengthText, &type, &handle, &rect );
  1348.     GetDialogItemText( handle, text );
  1349.     StringToNum( text, &length );
  1350.     
  1351.     GetDialogItemAsControl( dialog, kScrollRadioGroup, &tempControl );
  1352.     if ( GetControlValue( tempControl ) == 1 )
  1353.         bounds.right = length;
  1354.     else
  1355.         bounds.bottom = length;
  1356.     
  1357.     DisposeDialog( dialog );
  1358.     
  1359.     CreateScrollBarControl( window, &bounds, 0, 0, 100, 0, false, nil, &control );
  1360.  
  1361.     if ( control != nil )
  1362.         SetControlVisibility( control, false, false );
  1363.  
  1364.     return control;
  1365. }
  1366.  
  1367. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1368. //    Ä CreateTabs                                                        PUBLIC
  1369. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1370. //    Creates a standard push button.
  1371. //
  1372. ControlHandle
  1373. CreateTabs( WindowPtr window )
  1374. {
  1375.     enum { kEast = 1, kWest, kNorth, kSouth };
  1376.  
  1377.     DialogPtr                dialog;
  1378.     SInt16                    itemHit = 0;
  1379.     ControlRef                control = nil;
  1380.     ControlRef                handle;
  1381.     Str255                    text;
  1382.     Rect                    bounds = { 0, 0, 100, 300 };
  1383.     ControlTabSize            size;
  1384.     ControlTabDirection        direction;
  1385.     Boolean                    useIcons;
  1386.     ControlKeyFilterUPP        filterProc;
  1387.     short                    i;
  1388.     ControlTabInfoRec        infoRec;
  1389.     SInt32                    numTabs;
  1390.     unsigned char            *titles[4] = {"\pA","\pBunch","\pOf","\pTitles."};
  1391.     
  1392.     dialog = GetNewDialog( 2018, nil, (WindowPtr)-1L );
  1393.     if ( dialog == nil ) return nil;
  1394.  
  1395.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  1396.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  1397.  
  1398.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1399.  
  1400.     GetDialogItemAsControl( dialog, kTabNumberTabs, &control );
  1401.     SetEditTextKeyFilter( control, filterProc );
  1402.         
  1403.     while ( itemHit != kStdCancelItemIndex && itemHit != kStdOkItemIndex )
  1404.     {
  1405.         ModalDialog( nil, &itemHit );
  1406.         
  1407.         GetDialogItemAsControl( dialog, itemHit, &handle );
  1408.         if (itemHit == kTabUseIcon)
  1409.             SetControlValue( (ControlHandle)handle, !GetControlValue( (ControlHandle)handle ) );
  1410.     }
  1411.     
  1412.     if ( itemHit == kStdCancelItemIndex )
  1413.     {
  1414.         DisposeDialog( dialog );
  1415.         return nil;
  1416.     }
  1417.     
  1418.     GetDialogItemAsControl( dialog, kTabNumberTabs, &handle );
  1419.     GetDialogItemText( (Handle) handle, text );
  1420.     StringToNum( text, &numTabs );
  1421.     
  1422.     // determine which direction the user chose from the popup
  1423.     GetDialogItemAsControl( dialog, kTabDirectionPopup, &handle);
  1424.     switch (GetControlValue(handle))
  1425.     {
  1426.         case kEast:  direction = kControlTabDirectionEast;    break;
  1427.         case kWest:  direction = kControlTabDirectionWest;    break;
  1428.         default:
  1429.         case kNorth: direction = kControlTabDirectionNorth;    break;
  1430.         case kSouth: direction = kControlTabDirectionSouth;    break;
  1431.     }
  1432.     
  1433.     size = kControlTabSizeLarge;
  1434.     GetDialogItemAsControl( dialog, kTabSizeGroup, &handle);
  1435.     if (GetControlValue(handle) != 1)
  1436.         size = kControlTabSizeSmall;
  1437.  
  1438.     GetDialogItemAsControl( dialog, kTabUseIcon, &handle);
  1439.     
  1440.     useIcons = GetControlValue(handle);
  1441.  
  1442.     DisposeDialog( dialog );
  1443.     
  1444.     CreateTabsControl( window, &bounds, size, direction, numTabs, nil, &control );
  1445.     if ( control == nil ) return nil;
  1446.  
  1447.     SetControlVisibility( control, false, false );
  1448.  
  1449.     /**    now set the tab names manually **/
  1450.         
  1451.     infoRec.version = kControlTabInfoVersionZero;
  1452.     infoRec.iconSuiteID = useIcons ? 128 : 0;
  1453.     
  1454.     for(i=1;i<=numTabs;i++)
  1455.         {
  1456.             // cycle through the sample titles
  1457. //            memcpy(&infoRec.name,titles[(i-1) % 4], *titles[(i-1) % 4]+1);
  1458.             BlockMove(titles[(i-1) % 4], &infoRec.name, *titles[(i-1) % 4]+1);
  1459.                                  
  1460.             SetControlData(control, i, kControlTabInfoTag, sizeof(ControlTabInfoRec), (Ptr) &infoRec);
  1461.         }
  1462.     
  1463.     return control;
  1464. }
  1465.  
  1466.  
  1467.  
  1468.  
  1469. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1470. //    Ä CreatePushButton                                                        PUBLIC
  1471. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1472. //    Creates a standard push button.
  1473. //
  1474. ControlHandle
  1475. CreatePushButton( WindowPtr window )
  1476. {
  1477.     DialogPtr        dialog;
  1478.     SInt16            itemHit = 0;
  1479.     ControlHandle    control = nil;
  1480.     SInt16            type;
  1481.     Handle            handle;
  1482.     Rect            rect;
  1483.     Str255            text;
  1484.     Rect            bounds = { 0, 0, 22, 22 };
  1485.     Boolean            isDefault;
  1486.     SInt16            baseLine;
  1487.     ControlHandle    tempControl;
  1488.     
  1489.     dialog = GetNewDialog( 2012, nil, (WindowPtr)-1L );
  1490.     if ( dialog == nil ) return nil;
  1491.  
  1492.     SetDialogDefaultItem( dialog, kPushButtonOKButton );
  1493.     SetDialogCancelItem( dialog, kPushButtonCancelButton );
  1494.         
  1495.     while ( itemHit != kPushButtonCancelButton && itemHit != kPushButtonOKButton )
  1496.     {
  1497.         ModalDialog( nil, &itemHit );
  1498.         
  1499.         GetDialogItem( dialog, itemHit, &type, &handle, &rect );
  1500.         switch ( itemHit )
  1501.         {
  1502.             case kPushButtonDefaultCheck:
  1503.                 SetControlValue( (ControlHandle)handle, !GetControlValue( (ControlHandle)handle ) );
  1504.                 break;
  1505.         }
  1506.     }
  1507.     
  1508.     if ( itemHit == kPushButtonCancelButton )
  1509.     {
  1510.         DisposeDialog( dialog );
  1511.         return nil;
  1512.     }
  1513.     
  1514.     GetDialogItem( dialog, kPushButtonTitleText, &type, &handle, &rect );
  1515.     GetDialogItemText( handle, text );
  1516.     
  1517.     GetDialogItemAsControl( dialog, kPushButtonDefaultCheck, &tempControl );
  1518.     isDefault = (GetControlValue( tempControl ) == 1 );
  1519.         
  1520.     DisposeDialog( dialog );
  1521.     
  1522.     CreatePushButtonControl( window, &bounds, text, &control );
  1523.     if ( control == nil ) return nil;
  1524.  
  1525.     SetControlVisibility( control, false, false );
  1526.     
  1527.     if ( isDefault )
  1528.     {
  1529.         SetControlData( control, 0, kControlPushButtonDefaultTag, sizeof( isDefault ),
  1530.             (Ptr)&isDefault );
  1531.     }
  1532.     
  1533.     if ( GetBestControlRect( control, &bounds, &baseLine ) == noErr )
  1534.         SetControlBounds( control, &bounds );
  1535.     
  1536.     return control;
  1537. }
  1538.  
  1539. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1540. //    Ä CreateCheckBox                                                            PUBLIC
  1541. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1542. //    Creates a standard check box.
  1543. //
  1544. ControlHandle
  1545. CreateCheckBox( WindowPtr window )
  1546. {
  1547.     return CreateCheckBoxOrRadioButton( window, true );
  1548. }
  1549.  
  1550. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1551. //    Ä CreateRadioButton                                                            PUBLIC
  1552. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1553. //    Creates a standard radio button.
  1554. //
  1555. ControlHandle
  1556. CreateRadioButton( WindowPtr window )
  1557. {
  1558.     return CreateCheckBoxOrRadioButton( window, false );
  1559. }
  1560.  
  1561. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1562. //    Ä CreateCheckBoxOrRadioButton                                                PRIVATE
  1563. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1564. //    Creates a standard check box or radio button.
  1565. //
  1566. static ControlHandle
  1567. CreateCheckBoxOrRadioButton( WindowPtr window, Boolean isCheckBox )
  1568. {
  1569.     DialogRef        dialog;
  1570.     SInt16            itemHit = 0;
  1571.     ControlRef        control = nil;
  1572.     Handle            handle;
  1573.     Str255            text;
  1574.     Rect            bounds = { 0, 0, 22, 22 };
  1575.     SInt16            baseLine;
  1576.     Boolean             doAutoToggle;
  1577.     
  1578.     dialog = GetNewDialog( 2013, nil, (WindowPtr)-1L );
  1579.     if ( dialog == nil ) return nil;
  1580.  
  1581.     GetDialogItemAsControl(dialog, kCheckBoxTitleText, (ControlHandle *) &handle);
  1582.     
  1583.     if ( isCheckBox )
  1584.     {
  1585.         SetWTitle( (WindowPtr) dialog, "\pCheck Box" );
  1586.         SetDialogItemText( handle, "\pCheck Box");
  1587.     }
  1588.     else
  1589.     {
  1590.         SetWTitle( (WindowPtr) dialog, "\pRadio Button" );
  1591.         SetDialogItemText( handle, "\pRadio Button");
  1592.     }
  1593.  
  1594.     SetDialogDefaultItem( dialog, kCheckBoxOKButton );
  1595.     SetDialogCancelItem( dialog, kCheckBoxCancelButton );
  1596.         
  1597.     ShowWindow( GetDialogWindow( dialog ) );
  1598.     
  1599.     while ( itemHit != kCheckBoxCancelButton && itemHit != kCheckBoxOKButton )
  1600.     {
  1601.         ModalDialog( nil, &itemHit );
  1602.         
  1603.         if (itemHit == 5)
  1604.             {
  1605.                 GetDialogItemAsControl(dialog, 5, (ControlHandle *) &handle);
  1606.                 SetControlValue((ControlHandle) handle, !GetControlValue((ControlHandle) handle));
  1607.             }
  1608.     }
  1609.     
  1610.     if ( itemHit == kCheckBoxCancelButton )
  1611.     {
  1612.         DisposeDialog( dialog );
  1613.         return nil;
  1614.     }
  1615.     
  1616.     GetDialogItemAsControl(dialog, kCheckBoxTitleText, (ControlHandle *) &handle);
  1617.     GetDialogItemText( handle, text );
  1618.  
  1619.     GetDialogItemAsControl(dialog, 5, (ControlHandle *) &handle);
  1620.     doAutoToggle = GetControlValue((ControlHandle) handle) == 1;
  1621.     
  1622.     DisposeDialog( dialog );
  1623.  
  1624.     if ( isCheckBox )
  1625.         CreateCheckBoxControl( window, &bounds, text, doAutoToggle, &control );
  1626.     else
  1627.         CreateRadioButtonControl( window, &bounds, text, doAutoToggle, &control );
  1628.  
  1629.     if ( control == nil ) return nil;
  1630.  
  1631.     SetControlVisibility( control, false, false );
  1632.     
  1633.     if ( GetBestControlRect( control, &bounds, &baseLine ) == noErr )
  1634.         SetControlBounds( control, &bounds );
  1635.     
  1636.     return control;
  1637. }
  1638.  
  1639.  
  1640. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1641. //    Ä CreateImageWell                                                        PUBLIC
  1642. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1643. //    This routine creates an image well.
  1644. //
  1645. ControlHandle
  1646. CreateImageWell( WindowPtr window )
  1647. {
  1648.     DialogRef                    dialog;
  1649.     SInt16                        itemHit = 0;
  1650.     SInt16                        type;
  1651.     Handle                        handle;
  1652.     Rect                        rect;
  1653.     Rect                        bounds = { 0, 0, 0, 0 };
  1654.     Str255                        text;
  1655.     SInt32                        number;
  1656.     SInt32                        resID = 0;
  1657.     ControlKeyFilterUPP            filterProc;
  1658.     ControlRef                    tempControl;
  1659.     ControlButtonContentInfo        content;
  1660.     ControlRef                    control;
  1661.     
  1662.     dialog = GetNewDialog( 2011, nil, (WindowPtr)-1L );
  1663.     if ( dialog == nil ) return nil;
  1664.  
  1665.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1666.  
  1667.     GetDialogItemAsControl( dialog, kImageHeightText, &tempControl );
  1668.     SetEditTextKeyFilter( tempControl, filterProc );
  1669.  
  1670.     GetDialogItemAsControl( dialog, kImageWidthText, &tempControl );
  1671.     SetEditTextKeyFilter( tempControl, filterProc );
  1672.  
  1673.     GetDialogItemAsControl( dialog, kImageResIDText, &tempControl );
  1674.     SetEditTextKeyFilter( tempControl, filterProc );
  1675.  
  1676.     SetDialogDefaultItem( dialog, kImageOKButton );
  1677.     SetDialogCancelItem( dialog, kImageCancelButton );
  1678.         
  1679.     while ( itemHit != kImageCancelButton && itemHit != kImageOKButton )
  1680.     {
  1681.         ModalDialog( nil, &itemHit );
  1682.     }
  1683.     DisposeControlKeyFilterUPP( filterProc );
  1684.     
  1685.     if ( itemHit == kImageCancelButton )
  1686.     {
  1687.         DisposeDialog( dialog );
  1688.         return nil;
  1689.     }
  1690.     
  1691.     GetDialogItem( dialog, kImageHeightText, &type, &handle, &rect );
  1692.     GetDialogItemText( handle, text );
  1693.     StringToNum( text, &number );
  1694.     bounds.bottom = number;
  1695.     
  1696.     GetDialogItem( dialog, kImageWidthText, &type, &handle, &rect );
  1697.     GetDialogItemText( handle, text );
  1698.     StringToNum( text, &number );
  1699.     bounds.right = number;
  1700.     
  1701.     GetDialogItem( dialog, kImageResIDText, &type, &handle, &rect );
  1702.     GetDialogItemText( handle, text );
  1703.     StringToNum( text, &resID );
  1704.     content.u.resID = resID;
  1705.     
  1706.     GetDialogItemAsControl( dialog, kImageContentPopup, &tempControl );
  1707.     switch ( GetControlValue( tempControl ) )
  1708.     {
  1709.         case 1:    content.contentType = kControlContentIconSuiteRes;    break;
  1710.         case 2:    content.contentType = kControlContentCIconRes;        break;
  1711.         case 3:    content.contentType = kControlContentPictRes;        break;
  1712.         default:    content.contentType = kControlNoContent;            break;
  1713.     }
  1714.     
  1715.     DisposeDialog( dialog );
  1716.     
  1717.     CreateImageWellControl( window, &bounds, &content, &control );
  1718.  
  1719.     if ( control != nil )
  1720.         SetControlVisibility( control, false, false );
  1721.  
  1722.     return control;
  1723. }
  1724.  
  1725. ControlHandle
  1726. CreateList(WindowPtr window)
  1727. {
  1728.     ControlRef                myListControl;
  1729.     Rect                    bounds = { 50, 50, 200, 200 };
  1730.     AlertStdAlertParamRec    myAlertParam = {true, false, nil, "\pListBox", "\pListBoxAutoSize",nil, 1, 0, kWindowDefaultPosition};
  1731.     SInt16                    outItemHit;
  1732.     Boolean                    autoSize;
  1733.     ListDefSpec                listDef;
  1734.  
  1735.     StandardAlert(kAlertPlainAlert, "\pWould you like it to use kControlListBoxProc or kControlListBoxAutoSizeProc?",nil, 
  1736.                     &myAlertParam, &outItemHit);
  1737.  
  1738.     autoSize = outItemHit == 2;
  1739.     
  1740.     listDef.defType = kListDefStandardTextType;
  1741.  
  1742.     CreateListBoxControl( window, &bounds, autoSize, 30, 30, true, true, 50, 16, true,
  1743.         &listDef, &myListControl );
  1744.  
  1745.     if (myListControl)
  1746.     {
  1747.         ListHandle theList;
  1748.         Size actualSize;
  1749.         OSErr theError;
  1750.  
  1751.         SetControlVisibility( myListControl, false, false );
  1752.         
  1753.         theError = GetControlData(myListControl, kControlNoPart, kControlListBoxListHandleTag, 4, (Ptr) &theList, &actualSize);
  1754.         
  1755.         if (theError == noErr)
  1756.         {
  1757.             short i,j;
  1758.             Str255 theString;
  1759.             long theNum=1;
  1760.             Cell whichCell;
  1761.             
  1762.             for(i=0; i<30; i++)
  1763.                 for(j=0; j<30; j++)
  1764.                     {
  1765.                         NumToString(theNum, theString);
  1766.                         theNum++;
  1767.                         whichCell.h = i;
  1768.                         whichCell.v = j;
  1769.                         LSetCell(&theString[1], theString[0],whichCell, theList);
  1770.                     }
  1771.         }
  1772.     }
  1773.     return (myListControl);
  1774. }
  1775.  
  1776.  
  1777.  
  1778. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1779. //    Ä GetIconSize                                                            UTILITY
  1780. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1781. //    This routine attempts to get the height and width of the icon specified by resID.
  1782. //    It assumes that ICONs are always 32x32. For cicns, we go into the resource and look
  1783. //    at the pixmap's bounding rectangle.
  1784. //
  1785. static void
  1786. GetPictureSize( SInt16 resID, SInt32* height, SInt32* width )
  1787. {
  1788.     PicHandle        picture;
  1789.     
  1790.     *height = 0;
  1791.     *width = 0;
  1792.     
  1793.     picture = GetPicture( resID );
  1794.     if ( picture == nil ) return;
  1795.     
  1796.     *height = (**picture).picFrame.bottom - (**picture).picFrame.top;
  1797.     *width = (**picture).picFrame.right - (**picture).picFrame.left;
  1798. }
  1799.  
  1800. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1801. //    Ä GetIconSize                                                            UTILITY
  1802. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1803. //    This routine attempts to get the height and width of the icon specified by resID.
  1804. //    It assumes that ICONs are always 32x32. For cicns, we go into the resource and look
  1805. //    at the pixmap's bounding rectangle.
  1806. //
  1807. static void
  1808. GetIconSize( SInt16 resID, SInt32* height, SInt32* width )
  1809. {
  1810.     Handle        icon;
  1811.     
  1812.     *height = 0;
  1813.     *width = 0;
  1814.     
  1815.     icon = GetResource( 'ICON', resID );
  1816.     if ( icon == nil )
  1817.     {
  1818.         icon = GetResource( 'cicn', resID );
  1819.         if ( icon == nil ) return;
  1820.     
  1821.         *height = (**(CIconHandle)icon).iconPMap.bounds.bottom - (**(CIconHandle)icon).iconPMap.bounds.top;
  1822.         *width = (**(CIconHandle)icon).iconPMap.bounds.right - (**(CIconHandle)icon).iconPMap.bounds.left;
  1823.     }
  1824.     else
  1825.     {    
  1826.         *height = *width = 32;
  1827.     }
  1828. }
  1829.  
  1830. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1831. //    Ä NumericFilter                                                            PUBLIC
  1832. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  1833. //    This function is a key filter for edit text fields. It ensures that all input is
  1834. //    numeric. It also allows editing keys to pass thru so that the edit text actually
  1835. //    remains editable!
  1836. //
  1837. pascal ControlKeyFilterResult
  1838. NumericFilter( ControlHandle control, SInt16* keyCode, SInt16* charCode, EventModifiers* modifiers )
  1839. {
  1840. #pragma unused( control, keyCode, modifiers )
  1841.  
  1842.     if ( ((char)*charCode >= '0') && ((char)*charCode <= '9') )
  1843.         return kControlKeyFilterPassKey;
  1844.     
  1845.     switch ( *charCode )
  1846.     {
  1847.         case '-':
  1848.         case kLeftArrow:
  1849.         case kRightArrow:
  1850.         case kUpArrow:
  1851.         case kDownArrow:
  1852.         case kBackspace:
  1853.             return kControlKeyFilterPassKey;
  1854.  
  1855.         default:
  1856.             return kControlKeyFilterBlockKey;
  1857.     }
  1858. }
  1859.